/****************************************************************************
**
** Authors: Antonio Marcio A Menezes, Emanuel Grohs.
**
** This file is part of the Qt Board Game Framework.
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#include "gamestate.h"

using namespace qtbf;

/* This class saves all game state for future game continuation, undo mechanics or send over network purpouses. */
GameState::GameState(/* ILayoutStrategy layoutStrategy */)
{
    // super(layoutStrategy);
    setBackground(Color.GREEN);
    setPreferredSize(new Dimension(400, 400));
    setMinimumSize(new Dimension(400, 400));
}
// TODO String ou Player? Deve ser salvo!

/* Which player turn is. */
// protected String playerTurn;
protected int playerTurn;

/* If that player already made a move this turn. */
protected boolean moved = false;

/* Number of game players. */
protected int playerCount;

/* Number of game round. */
protected int nRound;

public int GameState::getPlayerCount()
{
    return playerCount;
}

public void setPlayerCount(int playerCount) {
    this.playerCount = playerCount;
}

public int getnRound() {
        return nRound;
}

public void incNRound() {
        this.nRound++;
}

public void setPlayerTurn(int playerTurn) {
        int old = this.playerTurn;
        this.playerTurn = playerTurn;
        firePropertyChange("playerVez", old, playerTurn);
}

/* Search the game state and return a zone with that name. */
public final Zona getZonaByName(String zoneName) {
        return getZonaByNameRecursive(zoneName, this);
}

private Zona getZonaByNameRecursive(String nomeZona, Container origem) {
        if (nomeZona != null) {
                if (nomeZona.equals(origem.getName())) {
                        return (Zona) origem;
                }
                for (Component c : origem.getComponents()) {
                        Zona zona = getZonaByNameRecursivo(nomeZona, (Container) c);
                        if (zona != null) {
                                return zona;
                        }
                }
        }
        return null;
}

/* Return a copy of this object. */
public Object clone() throws CloneNotSupportedException {
        // TODO Rever clone.
        return super.clone();
}

public int getPlayerTurn() {
        return playerTurn;
}

public boolean isMoved() {
        return moved;
}

public void setMove(boolean moved) {
        this.moved = moved;
}

// TODO pensar geito melhor
public LayoutManager getLayout() {
        if (getLayout() == null) {
                setLayout(new CircularLayoutStrategy());
        }
        return super.getLayout();
}

public void reorganiza(IPlayer modelo) {
        // TODO ninguem chama
}

// protected String[] playerNames;

// public void setPlayerNames(String[] playerNames) {
// this.playerNames = playerNames;
// }

// public String[] getPlayerNames() {
// return playerNames;
// }
